import logging
from typing import List

from Hogwarts.Homeworks.hw0718.api.wework import WeWork


class ApiContactMember(WeWork):

    def create_member(self, user_id: str, name: str, mobile: str, department: List[int]):
        data = {
            "method": 'post',
            "url": f"{self.base_url}/user/create",
            "params": {"access_token": self.token},
            "json": {
                "userid": user_id,
                "name": name,
                "mobile": mobile,
                "department": department
            }
        }

        return self.do_request(data)

    def query_member(self, user_id: str):
        data = {
            "method": 'get',
            "url": f"{self.base_url}/user/get",
            "params": {"access_token": self.token, "userid": user_id},
        }
        return self.do_request(data)

    def update(self, user_id: str, **kwargs):
        data = {
            "method": 'post',
            "url": f"{self.base_url}/user/update",
            "params": {"access_token": self.token},
            "json": {
                "userid": user_id
            }
        }
        data['json'].update(dict(kwargs))   # 更新自定义参数
        return self.do_request(data)

    def delete(self, user_id: str):
        data = {
            "method": 'get',
            "url": f"{self.base_url}/user/delete",
            "params": {"access_token": self.token, "userid": user_id},
        }
        return self.do_request(data)

    def get_dept_members(self, department_id: int):
        data = {
            "method": 'get',
            "url": f"{self.base_url}/user/simplelist",
            "params": {"access_token": self.token, "department_id": department_id},
        }
        return self.do_request(data)

    def check_member_ids(self):
        resp = self.get_dept_members(department_id=1)
        return [item['userid'] for item in resp.json().get('userlist')]

    def check_member_names(self):
        resp = self.get_dept_members(department_id=1)
        return [item['name'] for item in resp.json().get('userlist')]